﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cow.Module;

namespace Cow.Handler
{
    public class ExportMappingExtensionsHandler : ExportFromStringBuilder
    {
        public override string SuffixName
        {
            get { return "MoveTo.cs"; }
        }

        protected override string TemplatePath
        {
            get { return AppDomain.CurrentDomain.BaseDirectory + "/Template/MappingExtensions.txt"; }
        }

        protected override List<String> GetExportContent(Design design)
        {
            StringBuilder sb = new StringBuilder();
            // 添加字段赋值语句
            foreach (var definition in design.DefinitionInfo)
            {
                //模板中已经Id处理，跳过
                //非布局字段也跳过
                if (definition.Property.ToLower().Equals("id") ||
                    !definition.IsLayout)
                {
                    continue;
                }
                sb.AppendLine(String.Format("{0} = entity.{0},", definition.Property));
            }
            List<String> valueList = new List<string>();
            valueList.Add(design.ModuleName);
            valueList.Add(sb.ToString());
            valueList.Add(design.NameSpace);
            return valueList;
        }
    }
}
